/**
 * Source file: OnBlur_Disabillity_Claimant.ejs
 * Copyright (C) 2013 : Quantum Solutions
 * Id: $Id: OnBlur_DisabillityClaim.ejs 123 2013-04-29 20:29:19Z WillieVisagie55@gmail.com $
 * Date: $Date: 2013-04-29 22:29:19 +0200 (Mon, 29 Apr 2013) $
 */

var prevField = ""; 
function Field_onBlur(f) {
	prevField = f;
}

function Field_onFocus(f){
	//alert ("Field_onFocus:" + f.name );
	
	// only validate when we change fields
	// (ie can blur a field without leaving it! amazing! no!)
	if (f.name != prevField.name) {
		validateFields(prevField);
	}
}	

function validateFields(f) {
	 //alert("validateFields: "+f.name);

//Postal Code Validations X 5
    if(f.name=="Code") {
		CheckPostal("Suburb","Code");
    } else if(f.name=="ADPACode_3") {
		CheckPostal("ADPASuburb_2","ADPACode_3");
    } else if(f.name=="Address_EmpTOD_Code") {
		CheckPostal("Address_EmpTOD_Suburb","Address_EmpTOD_Code");
    } else if(f.name=="GP_Address_Code") {
		CheckPostal("GP_Address_Suburb","GP_Address_Code");	
    } else if(f.name=="PHS_Hosp_Address_Code") {
		CheckPostal("PHS_Hosp_Address_Suburb","PHS_Hosp_Address_Code");
//ID number Validations
    } else if(f.name=="IDNumber") {
		if (!IDNoValidater(EFormGetValue("IDNumber")) && EFormGetValue("IDNumber") != ""){
			alert("Claimant IDNumber is invalid: " + EFormGetValue("IDNumber"));				
			EFormSetFocus(EFormGetField("IDNumber"));  
		}
//Date Validations
	} else if (f.name=="Consult_Doc_Date") {
		if (!CheckDate(EFormGetValue("Consult_Doc_Date")) && EFormGetValue("Consult_Doc_Date") != ""){
			//alert("Invalid date: " + EFormGetValue("Consult_Doc_Date"));
			EFormSetFocus(EFormGetField("Consult_Doc_Date")); 
		}
	} else if (f.name=="Date_of_event") {
		if (!CheckDate(EFormGetValue("Date_of_event")) && EFormGetValue("Date_of_event") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_event"));
			EFormSetFocus(EFormGetField("Date_of_event")); 
		}
	} else if (f.name=="Date_Of_Injury") {
		if (!CheckDate(EFormGetValue("Date_Of_Injury")) && EFormGetValue("Date_Of_Injury") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Of_Injury"));
			EFormSetFocus(EFormGetField("Date_Of_Injury")); 
		}
	} else if (f.name=="Date_of_Accident") {
		if (!CheckDate(EFormGetValue("Date_of_Accident")) && EFormGetValue("Date_of_Accident") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Accident"));
			EFormSetFocus(EFormGetField("Date_of_Accident")); 
		}
	} else if (f.name=="Date_of_Adminssion_1") {
		if (!CheckDate(EFormGetValue("Date_of_Adminssion_1")) && EFormGetValue("Date_of_Adminssion_1") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Adminssion_1"));
			EFormSetFocus(EFormGetField("Date_of_Adminssion_1")); 
		}
	} else if (f.name=="Date_of_Adminssion_2") {
		if (!CheckDate(EFormGetValue("Date_of_Adminssion_2")) && EFormGetValue("Date_of_Adminssion_2") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Adminssion_2"));
			EFormSetFocus(EFormGetField("Date_of_Adminssion_2")); 
		}
	} else if (f.name=="Date_of_Adminssion_3") {
		if (!CheckDate(EFormGetValue("Date_of_Adminssion_3")) && EFormGetValue("Date_of_Adminssion_3") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Adminssion_3"));
			EFormSetFocus(EFormGetField("Date_of_Adminssion_3")); 
		}
	} else if (f.name=="Date_of_Adminssion_4") {
		if (!CheckDate(EFormGetValue("Date_of_Adminssion_4")) && EFormGetValue("Date_of_Adminssion_4") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Adminssion_4"));
			EFormSetFocus(EFormGetField("Date_of_Adminssion_4")); 
		}
	} else if (f.name=="Date_of_Discharge_1") {
		if (!CheckDate(EFormGetValue("Date_of_Discharge_1")) && EFormGetValue("Date_of_Discharge_1") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Discharge_1"));
			EFormSetFocus(EFormGetField("Date_of_Discharge_1")); 
		}
	} else if (f.name=="Date_of_Discharge_2") {
		if (!CheckDate(EFormGetValue("Date_of_Discharge_2")) && EFormGetValue("Date_of_Discharge_2") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Discharge_2"));
			EFormSetFocus(EFormGetField("Date_of_Discharge_2")); 
		}
	} else if (f.name=="Date_of_Discharge_3") {
		if (!CheckDate(EFormGetValue("Date_of_Discharge_3")) && EFormGetValue("Date_of_Discharge_3") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Discharge_3"));
			EFormSetFocus(EFormGetField("Date_of_Discharge_3")); 
		}
	} else if (f.name=="Date_of_Discharge_4") {
		if (!CheckDate(EFormGetValue("Date_of_Discharge_4")) && EFormGetValue("Date_of_Discharge_4") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_Discharge_4"));
			EFormSetFocus(EFormGetField("Date_of_Discharge_4")); 
		}
	} else if (f.name=="ConsultationPeriodFrom") {
		if (!CheckDate(EFormGetValue("ConsultationPeriodFrom")) && EFormGetValue("ConsultationPeriodFrom") != ""){
			//alert("Invalid date: " + EFormGetValue("ConsultationPeriodFrom"));
			EFormSetFocus(EFormGetField("ConsultationPeriodFrom")); 
		}
	} else if (f.name=="ConsultationPeriodTo") {
		if (!CheckDate(EFormGetValue("ConsultationPeriodTo")) && EFormGetValue("ConsultationPeriodTo") != ""){
			//alert("Invalid date: " + EFormGetValue("ConsultationPeriodTo"));
			EFormSetFocus(EFormGetField("ConsultationPeriodTo")); 
		}
	} else if (f.name=="ConsultationPeriodFrom_2") {
		if (!CheckDate(EFormGetValue("ConsultationPeriodFrom_2")) && EFormGetValue("ConsultationPeriodFrom_2") != ""){
			//alert("Invalid date: " + EFormGetValue("ConsultationPeriodFrom_2"));
			EFormSetFocus(EFormGetField("ConsultationPeriodFrom_2")); 
		}
	} else if (f.name=="ConsultationPeriodTo_2") {
		if (!CheckDate(EFormGetValue("ConsultationPeriodTo_2")) && EFormGetValue("ConsultationPeriodTo_2") != ""){
			//alert("Invalid date: " + EFormGetValue("ConsultationPeriodTo_2"));
			EFormSetFocus(EFormGetField("ConsultationPeriodTo_2")); 
		}
	} else if (f.name=="Date_Partaking_Duties") {
		if (!CheckDate(EFormGetValue("Date_Partaking_Duties")) && EFormGetValue("Date_Partaking_Duties") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Partaking_Duties"));
			EFormSetFocus(EFormGetField("Date_Partaking_Duties")); 
		}
	} else if (f.name=="Date_Actively_Engaged") {
		if (!CheckDate(EFormGetValue("Date_Actively_Engaged")) && EFormGetValue("Date_Actively_Engaged") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Actively_Engaged"));
			EFormSetFocus(EFormGetField("Date_Actively_Engaged")); 
		}
	} else if (f.name=="Date_Return_Occupation") {
		if (!CheckDateNoFutureCheck(EFormGetValue("Date_Return_Occupation")) && EFormGetValue("Date_Return_Occupation") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Return_Occupation"));
			EFormSetFocus(EFormGetField("Date_Return_Occupation")); 
		}
	} else if (f.name=="Date_Similar_Occupation") {
		if (!CheckDateNoFutureCheck(EFormGetValue("Date_Similar_Occupation")) && EFormGetValue("Date_Similar_Occupation") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Similar_Occupation"));
			EFormSetFocus(EFormGetField("Date_Similar_Occupation")); 
		}
	} else if (f.name=="Employment_Date_1") {
		if (!CheckDate(EFormGetValue("Employment_Date_1")) && EFormGetValue("Employment_Date_1") != ""){
			//alert("Invalid date: " + EFormGetValue("Employment_Date_1"));
			EFormSetFocus(EFormGetField("Employment_Date_1")); 
		}
	} else if (f.name=="Employment_Date_2") {
		if (!CheckDate(EFormGetValue("Employment_Date_2")) && EFormGetValue("Employment_Date_2") != ""){
			//alert("Invalid date: " + EFormGetValue("Employment_Date_2"));
			EFormSetFocus(EFormGetField("Employment_Date_2")); 
		}
	} else if (f.name=="Employment_Date_3") {
		if (!CheckDate(EFormGetValue("Employment_Date_3")) && EFormGetValue("Employment_Date_3") != ""){
			//alert("Invalid date: " + EFormGetValue("Employment_Date_3"));
			EFormSetFocus(EFormGetField("Employment_Date_3")); 
		}
	} else if (f.name=="Employment_Date_4") {
		if (!CheckDate(EFormGetValue("Employment_Date_4")) && EFormGetValue("Employment_Date_4") != ""){
			//alert("Invalid date: " + EFormGetValue("Employment_Date_4"));
			EFormSetFocus(EFormGetField("Employment_Date_4")); 
		}

//Telephone number Validations
	} else if(f.name=="Work_Number") {
		if (!TelNoValidater(EFormGetValue("Work_Number")) && EFormGetValue("Work_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Work_Number"));				
			EFormSetFocus(EFormGetField("Work_Number"));  
		} 
	} else if(f.name=="Cell_Number") {
		if (!TelNoValidater(EFormGetValue("Cell_Number")) && EFormGetValue("Cell_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Cell_Number"));				
			EFormSetFocus(EFormGetField("Cell_Number"));  
		} 
	} else if(f.name=="Home_Number") {
		if (!TelNoValidater(EFormGetValue("Home_Number")) && EFormGetValue("Home_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Home_Number"));				
			EFormSetFocus(EFormGetField("Home_Number"));  
		} 
	} else if(f.name=="GPTelWork") {
		if (!TelNoValidater(EFormGetValue("GPTelWork")) && EFormGetValue("GPTelWork") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("GPTelWork"));				
			EFormSetFocus(EFormGetField("GPTelWork"));  
		} 
	} else if(f.name=="PHS_PhoneNumber") {
		if (!TelNoValidater(EFormGetValue("PHS_PhoneNumber")) && EFormGetValue("PHS_PhoneNumber") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("PHS_PhoneNumber"));				
			EFormSetFocus(EFormGetField("PHS_PhoneNumber"));  
		} 
	} else if(f.name=="HealthPro_Tel_1") {
		if (!TelNoValidater(EFormGetValue("HealthPro_Tel_1")) && EFormGetValue("HealthPro_Tel_1") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("HealthPro_Tel_1"));				
			EFormSetFocus(EFormGetField("HealthPro_Tel_1"));  
		} 
	} else if(f.name=="HealthPro_Tel_2") {
		if (!TelNoValidater(EFormGetValue("HealthPro_Tel_2")) && EFormGetValue("HealthPro_Tel_2") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("HealthPro_Tel_2"));				
			EFormSetFocus(EFormGetField("HealthPro_Tel_2"));  
		} 
	} else if(f.name=="HealthPro_Tel_3") {
		if (!TelNoValidater(EFormGetValue("HealthPro_Tel_3")) && EFormGetValue("HealthPro_Tel_3") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("HealthPro_Tel_3"));				
			EFormSetFocus(EFormGetField("HealthPro_Tel_3"));  
		} 
	} else if(f.name=="HealthPro_Tel_4") {
		if (!TelNoValidater(EFormGetValue("HealthPro_Tel_4")) && EFormGetValue("HealthPro_Tel_4") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("HealthPro_Tel_4"));				
			EFormSetFocus(EFormGetField("HealthPro_Tel_4"));  
		} 
	} else if(f.name=="Specialist_TelNo_1") {
		if (!TelNoValidater(EFormGetValue("Specialist_TelNo_1")) && EFormGetValue("Specialist_TelNo_1") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Specialist_TelNo_1"));				
			EFormSetFocus(EFormGetField("Specialist_TelNo_1"));  
		} 
	} else if(f.name=="Specialist_TelNo_2") {
		if (!TelNoValidater(EFormGetValue("Specialist_TelNo_2")) && EFormGetValue("Specialist_TelNo_2") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Specialist_TelNo_2"));				
			EFormSetFocus(EFormGetField("Specialist_TelNo_2"));  
		} 
	} else if(f.name=="Specialist_TelNo_3") {
		if (!TelNoValidater(EFormGetValue("Specialist_TelNo_3")) && EFormGetValue("Specialist_TelNo_3") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Specialist_TelNo_3"));				
			EFormSetFocus(EFormGetField("Specialist_TelNo_3"));  
		} 
	}else if(f.name=="Specialist_TelNo_4") {
		if (!TelNoValidater(EFormGetValue("Specialist_TelNo_4")) && EFormGetValue("Specialist_TelNo_4") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Specialist_TelNo_4"));				
			EFormSetFocus(EFormGetField("Specialist_TelNo_4"));  
		} 
	}
	return true;
}
